package com.JJTZ.android.view;



import com.JJTZ.android.R;


import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.GeolocationPermissions;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.RenderPriority;
import android.webkit.WebStorage;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebViewActivity extends MasterActivity{
	private WebView wv_View;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.web_view);
		
		
		Intent intent = getIntent();
        String url = intent.getStringExtra("url");
		Log.i("post", url);
		this.initSettings(); 
		 
		wv_View.loadUrl(url); 
	}
	
	private WebViewClient mWebViewClient = new WebViewClient() { 
        @Override 
        public boolean shouldOverrideUrlLoading(WebView view, String url) { 
        	wv_View.loadUrl(url); 
            return true; 
        } 
 
        @Override 
        public void onPageFinished(WebView view, String url) { 
            super.onPageFinished(view, url); 
        } 
 
        @Override 
        public void onPageStarted(WebView view, String url, Bitmap favicon) { 
            super.onPageStarted(view, url, favicon); 
        } 
    }; 
 
    private WebChromeClient mChromeClient = new WebChromeClient() { 
 
        private View myView = null; 
        private CustomViewCallback myCallback = null; 
        
        @Override
        public void onCloseWindow(WebView wv){
        	Log.i("?��?", "121212112");
        }
        // ??��??? �??WebChromeClinet�???��? 
        @Override 
        public void onGeolocationPermissionsShowPrompt(String origin, 
                GeolocationPermissions.Callback callback) { 
            callback.invoke(origin, true, false); 
            super.onGeolocationPermissionsShowPrompt(origin, callback); 
        } 
 
        // ?��??��?�??容�?�??WebChromeClinet�???��? 
        @Override 
        public void onExceededDatabaseQuota(String url, 
                String databaseIdentifier, long currentQuota, 
                long estimatedSize, long totalUsedQuota, 
                WebStorage.QuotaUpdater quotaUpdater) { 
 
            quotaUpdater.updateQuota(estimatedSize * 2); 
        } 
 
        @Override 
        public void onReachedMaxAppCacheSize(long spaceNeeded, 
                long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) { 
 
            quotaUpdater.updateQuota(spaceNeeded * 2); 
        } 
 
        @Override 
        public void onShowCustomView(View view, CustomViewCallback callback) { 
            if (myCallback != null) { 
                myCallback.onCustomViewHidden(); 
                myCallback = null; 
                return; 
            } 
 
            ViewGroup parent = (ViewGroup) wv_View.getParent(); 
            parent.removeView(wv_View); 
            parent.addView(view); 
            myView = view; 
            myCallback = callback; 
            mChromeClient = this; 
        } 
 
        @Override 
        public void onHideCustomView() { 
            if (myView != null) { 
                if (myCallback != null) { 
                    myCallback.onCustomViewHidden(); 
                    myCallback = null; 
                } 
 
                ViewGroup parent = (ViewGroup) myView.getParent(); 
                parent.removeView(myView); 
                parent.addView(wv_View); 
                myView = null; 
            } 
        } 
    }; 
 
    @SuppressLint("SetJavaScriptEnabled") 
    @SuppressWarnings("deprecation") 
    private void initSettings() { 
     
        setContentView(R.layout.web_view); 
        wv_View = (WebView) findViewById(R.id.wv_View); 
 
        WebSettings webSettings = wv_View.getSettings(); 
        webSettings.setJavaScriptEnabled(true); 
 
        webSettings.setDomStorageEnabled(true); 
 
        webSettings.setAppCacheEnabled(true); 
        String appCacheDir = this.getApplicationContext() 
                .getDir("cache", Context.MODE_PRIVATE).getPath(); 
        webSettings.setAppCachePath(appCacheDir); 
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); 
        webSettings.setAppCacheMaxSize(1024 * 1024 * 10);
        webSettings.setAllowFileAccess(true); 
 
        webSettings.setDatabaseEnabled(true); 
        String databaseDir = this.getApplicationContext() 
                .getDir("database", Context.MODE_PRIVATE).getPath(); 
        webSettings.setDatabasePath(databaseDir);
 
        webSettings.setGeolocationEnabled(true); 
        webSettings.setGeolocationDatabasePath(databaseDir); 
 
        webSettings.setPluginsEnabled(true); 
        webSettings.setRenderPriority(RenderPriority.HIGH); 
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true); 
 
        wv_View.setWebChromeClient(mChromeClient); 
        wv_View.setWebViewClient(mWebViewClient); 
    } 
}
